import 'package:flutter/material.dart';

class Widget_ClipPath_Page extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text("ClipPath"),
          ),
          body: Center(
            child: ClipPath(
              clipper: TriangleCliper(),
              child: Image.asset(
                "images/app.png",
                width: 100.0,
                height: 100.0,
                fit: BoxFit.cover,
              ),
            ),
          )
      ),
    );
  }
}

class TriangleCliper extends CustomClipper<Path> {
  //获取裁剪范围
  @override
  Path getClip(Size size) {
    //左上角为(0,0)
    var path = Path();
    path.moveTo(50.0, 50.0);//起始点
    path.lineTo(50.0, 0);//(50.0,50.0)->(50.0, 0)
    path.lineTo(100.0, 100.0);//(50.0,0)->(100.0, 100.0)
    path.close();//
    return path;
  }

  //是否重新裁剪
  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) {
    return true;
  }

}

/**
 * 路径裁剪
 *
 * ClipPath({
 * Key key,
 * this.clipper, //裁剪路径
 * this.clipBehavior = Clip.antiAlias,
 * Widget child
 * })
 */
